from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-11 14:12:07.452016
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 11, Sep, 2021
Time: 14:12:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1089
Nobs: 411.000 HQIC: -46.6407
Log likelihood: 4497.55 FPE: 3.91778e-21
AIC: -46.9888 Det(Omega_mle): 3.15557e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.434568 0.093061 4.670 0.000
L1.Burgenland 0.104646 0.048243 2.169 0.030
L1.Kärnten -0.113788 0.023999 -4.741 0.000
L1.Niederösterreich 0.173871 0.103601 1.678 0.093
L1.Oberösterreich 0.123780 0.101344 1.221 0.222
L1.Salzburg 0.283765 0.050553 5.613 0.000
L1.Steiermark 0.020436 0.066986 0.305 0.760
L1.Tirol 0.108271 0.052917 2.046 0.041
L1.Vorarlberg -0.111230 0.047646 -2.334 0.020
L1.Wien -0.016922 0.092188 -0.184 0.854
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.015332 0.215637 0.071 0.943
L1.Burgenland -0.045939 0.111788 -0.411 0.681
L1.Kärnten 0.037467 0.055609 0.674 0.500
L1.Niederösterreich -0.214563 0.240061 -0.894 0.371
L1.Oberösterreich 0.490162 0.234829 2.087 0.037
L1.Salzburg 0.304901 0.117139 2.603 0.009
L1.Steiermark 0.112828 0.155218 0.727 0.467
L1.Tirol 0.314854 0.122616 2.568 0.010
L1.Vorarlberg 0.001673 0.110404 0.015 0.988
L1.Wien -0.005152 0.213614 -0.024 0.981
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.249499 0.047468 5.256 0.000
L1.Burgenland 0.090489 0.024608 3.677 0.000
L1.Kärnten -0.001754 0.012241 -0.143 0.886
L1.Niederösterreich 0.207150 0.052844 3.920 0.000
L1.Oberösterreich 0.169860 0.051692 3.286 0.001
L1.Salzburg 0.033204 0.025786 1.288 0.198
L1.Steiermark 0.018858 0.034168 0.552 0.581
L1.Tirol 0.067445 0.026991 2.499 0.012
L1.Vorarlberg 0.059113 0.024303 2.432 0.015
L1.Wien 0.107852 0.047022 2.294 0.022
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181237 0.046410 3.905 0.000
L1.Burgenland 0.048973 0.024059 2.036 0.042
L1.Kärnten -0.006652 0.011968 -0.556 0.578
L1.Niederösterreich 0.137191 0.051666 2.655 0.008
L1.Oberösterreich 0.318708 0.050540 6.306 0.000
L1.Salzburg 0.100258 0.025211 3.977 0.000
L1.Steiermark 0.132015 0.033406 3.952 0.000
L1.Tirol 0.075471 0.026390 2.860 0.004
L1.Vorarlberg 0.056812 0.023761 2.391 0.017
L1.Wien -0.044285 0.045974 -0.963 0.335
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209888 0.092127 2.278 0.023
L1.Burgenland -0.055934 0.047759 -1.171 0.242
L1.Kärnten -0.034749 0.023758 -1.463 0.144
L1.Niederösterreich 0.115446 0.102561 1.126 0.260
L1.Oberösterreich 0.167512 0.100326 1.670 0.095
L1.Salzburg 0.257326 0.050045 5.142 0.000
L1.Steiermark 0.079891 0.066314 1.205 0.228
L1.Tirol 0.123543 0.052385 2.358 0.018
L1.Vorarlberg 0.116788 0.047168 2.476 0.013
L1.Wien 0.024660 0.091262 0.270 0.787
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028020 0.071487 0.392 0.695
L1.Burgenland 0.024458 0.037059 0.660 0.509
L1.Kärnten 0.052364 0.018435 2.840 0.005
L1.Niederösterreich 0.211635 0.079584 2.659 0.008
L1.Oberösterreich 0.333937 0.077849 4.290 0.000
L1.Salzburg 0.045131 0.038833 1.162 0.245
L1.Steiermark -0.005583 0.051457 -0.109 0.914
L1.Tirol 0.112988 0.040649 2.780 0.005
L1.Vorarlberg 0.066802 0.036601 1.825 0.068
L1.Wien 0.131068 0.070816 1.851 0.064
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187548 0.087554 2.142 0.032
L1.Burgenland 0.019320 0.045388 0.426 0.670
L1.Kärnten -0.057260 0.022579 -2.536 0.011
L1.Niederösterreich -0.112499 0.097470 -1.154 0.248
L1.Oberösterreich 0.190711 0.095346 2.000 0.045
L1.Salzburg 0.030338 0.047561 0.638 0.524
L1.Steiermark 0.299546 0.063022 4.753 0.000
L1.Tirol 0.486036 0.049785 9.763 0.000
L1.Vorarlberg 0.069329 0.044827 1.547 0.122
L1.Wien -0.110207 0.086732 -1.271 0.204
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158920 0.095135 1.670 0.095
L1.Burgenland -0.006747 0.049319 -0.137 0.891
L1.Kärnten 0.061826 0.024534 2.520 0.012
L1.Niederösterreich 0.184197 0.105910 1.739 0.082
L1.Oberösterreich -0.130205 0.103602 -1.257 0.209
L1.Salzburg 0.237034 0.051680 4.587 0.000
L1.Steiermark 0.159892 0.068479 2.335 0.020
L1.Tirol 0.051223 0.054096 0.947 0.344
L1.Vorarlberg 0.127001 0.048708 2.607 0.009
L1.Wien 0.159512 0.094242 1.693 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.484436 0.051610 9.386 0.000
L1.Burgenland -0.010935 0.026755 -0.409 0.683
L1.Kärnten -0.009765 0.013309 -0.734 0.463
L1.Niederösterreich 0.210493 0.057455 3.664 0.000
L1.Oberösterreich 0.261871 0.056203 4.659 0.000
L1.Salzburg 0.023005 0.028036 0.821 0.412
L1.Steiermark -0.026231 0.037149 -0.706 0.480
L1.Tirol 0.066209 0.029347 2.256 0.024
L1.Vorarlberg 0.056599 0.026424 2.142 0.032
L1.Wien -0.052419 0.051126 -1.025 0.305
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020518 0.078753 0.138633 0.135178 0.040454 0.073517 -0.002264 0.173143
Kärnten 0.020518 1.000000 -0.045773 0.126542 0.046822 0.070532 0.455033 -0.094378 0.091741
Niederösterreich 0.078753 -0.045773 1.000000 0.284545 0.082076 0.267750 0.020985 0.140238 0.261981
Oberösterreich 0.138633 0.126542 0.284545 1.000000 0.182359 0.285735 0.156493 0.100704 0.138295
Salzburg 0.135178 0.046822 0.082076 0.182359 1.000000 0.126899 0.056185 0.103109 0.049014
Steiermark 0.040454 0.070532 0.267750 0.285735 0.126899 1.000000 0.131097 0.088571 -0.024382
Tirol 0.073517 0.455033 0.020985 0.156493 0.056185 0.131097 1.000000 0.038298 0.116793
Vorarlberg -0.002264 -0.094378 0.140238 0.100704 0.103109 0.088571 0.038298 1.000000 -0.047957
Wien 0.173143 0.091741 0.261981 0.138295 0.049014 -0.024382 0.116793 -0.047957 1.000000